#!/usr/bin/python3
# -*- coding: utf-8 -*-
'''
@File    :  config.py
@Time    :  2022/05/10 09:25:03
@Author  :  HHLiang
@Contact :  sternapeg@qq.com
@Version :  1.0
@Desc    :  当前作用
'''
import yaml


def getYamlconfig(product):
    """
    它读取 config.yaml 文件并返回文件中键的值。
    
    :param product: config.yaml 文件中的产品名称
    :return: 6 个值的元组。
    """

    f = open('config.yaml', 'r', encoding='utf-8')  # open方法打开直接读出来
    cfg = f.read()  # 读出来是字符串
    d = yaml.load(cfg, Loader=yaml.FullLoader)  # 用FullLoader可以yaml解析变得安全
    f.close()
    APIKEY = d[product]['apikey']
    product_id = d[product]['product_id']
    product_id = str(product_id)

    device_id = d[product]['device_id']
    device_id = str(device_id)

    auth_info = d[product]['auth_info']
    auth_info = str(auth_info)

    host = d[product]['host']
    host = str(host)

    port = d[product]['port']
    # port = str(port)

    return(APIKEY, product_id, device_id, auth_info, host, port)


def config_run(a):
    """
    它读取一个 yaml 文件并返回一个字典
    :return: 配置文件的字典。
    """
    product = a  # 需要根据个人情况自行修改
    cfg = getYamlconfig(product)
    # print(cfg)
    return cfg


if __name__ == '__main__':
    print(config_run('A1'))
